<!DOCTYPE html>
<html lang="zh">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    

<script>

// flat(n)用于将多维数组扁平化，n表示扁平化几层

let arr = [1,2,[3,[4,[5,[6,[7,8]]]]]];

let res1 = arr.flat(3);
console.log( res1 );// [1, 2, 3, 4, 5, [6,[7,8]]]

let res2 = arr.flat(5);
console.log( res2 );// [1, 2, 3, 4, 5, 6, 7, 8]

let res3 = arr.flat(8);
console.log( res3 );// [1, 2, 3, 4, 5, 6, 7, 8]

let res4 = arr.flat(Infinity);
console.log( res4 );// [1, 2, 3, 4, 5, 6, 7, 8]

</script>
</body>
</html>